const  fs   = require('fs');
const  koa  = require('koa');
let  app=new  koa();
function asyncReadFile() {
   return new Promise(function(resolve,reject) {
      fs.readFile('./index.html',(err,data)=>{
        // 1:失败，err  2：成功需要data
          if(err) {
             reject(err);
             return;
          }
          // 成功
          resolve(data);
      });
   });
}


app.use(async (ctx)=>{
        if(ctx.url==='/') {
          let  data=await  asyncReadFile();
          ctx.body=data;
          // 设置响应头
          ctx.set('content-type','text/html;charset=utf-8');  //content-type: text/html;charset=utf-8
        } else {
             ctx.body='ok';
        }
    });

app.listen(1000);
